﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace AcesHigh.GUI
{
    class PictureCard : PictureBox
    {
        private Card card;
        private Bitmap faceUpImage;
        private Bitmap faceDownImage;

        public Suit CardSuit
        {
            get { return card.Suit; }
        }

        public Rank CardRank
        {
            get { return card.Rank; }
        }

       
        public PictureCard(Card card, String faceUpImage) : this(card, faceUpImage, null)
        { }

        public PictureCard(Card card, String faceUpImage, String faceDownImage)
        {
            this.card = card;
            this.faceUpImage = new Bitmap(faceUpImage);
            this.faceDownImage = new Bitmap(faceDownImage);
            SetSizeMode();
        }

        internal void showFaceUpImage()
        {
            this.Image = faceUpImage;
        }

        /**
         * Shows the card faced down if the facedown image has been set
         * otherwise shows the card face up.
         */
        internal void showFaceDownImage()
        {
            if (faceDownImage != null)
            {
                this.Image = faceDownImage;
            }
            else
            {
                showFaceUpImage();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                faceDownImage.Dispose();
                faceUpImage.Dispose();
                base.Dispose(disposing);
            }
        }

        protected void SetSizeMode() {
            this.SizeMode = PictureBoxSizeMode.AutoSize;
        }

        internal bool IsLowerValue(PictureCard testPictureCard)
        {
            return (this.card.IsLowerValue(testPictureCard.card));
        }
    }
}
